package com.twu.biblioteca.main.menu;

import com.twu.biblioteca.main.App;

import java.util.Enumeration;
import java.util.Iterator;

public enum MenuItem {

    //TODO: Add missing items
    LOGIN(1,"Login",new MenuAction() {
        @Override
        public void performAction(App app) {
            //To change body of implemented methods use File | Settings | File Templates.
            app.login();
        }
    }),
    SHOW_ALL_MOVIES(2,"Show all movies", new MenuAction() {
        @Override
        public void performAction(App app) {
            app.displayAllMovies();
        }
    }),
    SHOW_ALL(3,"Show all books", new MenuAction() {
        @Override
        public void performAction(App app) {
            app.displayAllBooks();
        }
    }),RESERVE(4, "Reserve book", new MenuAction() {
        @Override
        public void performAction(App app) {
            app.reserveBook();
        }
    }),

    CHECK_MEMBERSHIP(5,"Check Membership Details", new MenuAction() {
        @Override
        public void performAction(App app) {
            app.checkMembership();
        }
    })
    ,EXIT(6, "Exit", new MenuAction() {
        @Override
        public void performAction(App app) {
            app.exit();
        }
    });

    private final int menuItemId;
    private final String menuItemDesc;
    private final MenuAction action;

    MenuItem(int menuItemId, String menuItemDesc, MenuAction action) {
        //To change body of created methods use File | Settings | File Templates.
        this.menuItemId = menuItemId;
        this.menuItemDesc = menuItemDesc;
        this.action = action;
    }

    public void performAction(App app){
        action.performAction(app);

    }

    public static MenuItem itemFor(int menuId){
        //TODO: Iteate through all items and get the matching item - else return NULL
       for(MenuItem menuItem:MenuItem.values()){
           if(menuItem.getMenuItemId()==menuId)
               return menuItem;
       }
        return null;
    }

    public int getMenuItemId(){
        return this.menuItemId;
    }

    public String getMenuItemDesc(){
        return this.menuItemDesc;
    }

}
